package demo05

/**
 * @author xiaoZhao
 * @date 2022/7/1
 * @describe 混入
 */
object Test14_TraitMixin {
  def main(args: Array[String]): Unit = {
    val student = new Student14
    student.study()
    student.increase()

    student.play()
    student.increase()

    student.dating()
    student.increase()
    println("==================")
    // 动态混入
    val studentWithTalent = new Student14 with Talent {
      override def singing(): Unit = println("student is good at singing")

      override def dancing(): Unit = println("student is good at dancing")
    }
    studentWithTalent.sayHello()
    studentWithTalent.play()
    studentWithTalent.increase()
    studentWithTalent.dating()
    studentWithTalent.singing()
    studentWithTalent.dancing()
  }
}

trait Konwledge {
  var amout: Int = 0

  def increase(): Unit
}

trait Talent {
  def singing(): Unit

  def dancing(): Unit
}

class Student14 extends Person13 with Yong with Konwledge {
  // 重写冲突的属性
  override val name: String = "student"

  // 实现抽象方法
  override def dating(): Unit = println(s"Student $name is dating")

  def study() = println(s"studnt $name is study")

  //
  override def sayHello(): Unit = {
    super.sayHello()
    println(s"hello from: student $name")
  }

  override def increase(): Unit = {
    amout += 1
    println(s"student $name knoledge increaseed: $amout")
  }
}